<%= page_title "Outbound Webhooks" %>

<% usages = OutboundWebhookStage.pluck(:outbound_webhook_id, :stage_id).group_by(&:first).map { |id, s| [id, s.size] }.to_h  %>

<section class="clearfix">
  <table class="table table-hover table-condensed">
    <thead>
    <tr>
      <th>Name</th>
      <th>Url</th>
      <th>Auth</th>
      <th>Global</th>
      <th>SSL</th>
      <th>Usages</th>
      <th>Actions</th>
    </tr>
    </thead>

    <tbody>
    <% @outbound_webhooks.each do |outbound_webhook| %>
      <tr>
        <td><%= outbound_webhook.name %></td>
        <td><%= outbound_webhook.url %></td>
        <td><%= outbound_webhook.auth_type %></td>
        <td><%= outbound_webhook.global ? "YES" : "-" %></td>
        <td><%= outbound_webhook.ssl? ? "YES" : "-" %></td>
        <td><%= usages[outbound_webhook.id] || 0 %></td>
        <td><%= link_to "Edit", outbound_webhook %></td>
      </tr>
    <% end %>
    </tbody>
  </table>

  <div class="admin-actions">
    <%= paginate @pagy %>
  </div>
</section>
